return G_SOURCE_REMOVE;
}
+static gint inhibit_count;
+static GMainLoop *loop;
+
+void
+reftest_inhibit_snapshot (void)
+{
+ inhibit_count++;
+}
+
+void
+reftest_uninhibit_snapshot (void)
+{
+ g_assert (inhibit_count > 0);
+ inhibit_count--;
+
+ if (inhibit_count == 0)
+ g_idle_add (quit_when_idle, loop);
+}
+
static void
-check_for_draw (GdkEvent *event, gpointer loop)
+check_for_draw (GdkEvent *event, gpointer data)
{
if (event->type == GDK_EXPOSE)
{
- g_idle_add (quit_when_idle, loop);
+ reftest_uninhibit_snapshot ();
gdk_event_handler_set ((GdkEventFunc) gtk_main_do_event, NULL, NULL);
}
{
cairo_surface_t *surface;
cairo_pattern_t *bg;
- GMainLoop *loop;
cairo_t *cr;
g_assert (gtk_widget_get_realized (widget));
loop = g_main_loop_new (NULL, FALSE);
+
/* We wait until the widget is drawn for the first time.
* We can not wait for a GtkWidget::draw event, because that might not
* happen if the window is fully obscured by windowed child widgets.
* Alternatively, we could wait for an expose event on widget's window.
- * Both of these are rather hairy, not sure what's best. */
- gdk_event_handler_set (check_for_draw, loop, NULL);
+ * Both of these are rather hairy, not sure what's best.
+ *
+ * We also use an inhibit mechanism, to give module functions a chance
+ * to delay the snapshot.
+ */
+ reftest_inhibit_snapshot ();
+ gdk_event_handler_set (check_for_draw, NULL, NULL);
g_main_loop_run (loop);
surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
--- /dev/null
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_REFTEST_H__
+#define __GTK_REFTEST_H__
+
+G_BEGIN_DECLS
+
+void reftest_inhibit_snapshot (void);
+void reftest_uninhibit_snapshot (void);
+
+G_END_DECLS
+
+#endif /* __GTK_REFTEST_H__ */